/**
 * 框架基础
 */

(function (o) {

  //外边方法
  o.login = {
    autoload : function(isFirst){
       if(isFirst)
	     _event.initLogin();
    }
  };

  //内部方法
  var _event = {
	  initLogin : function(){

		  $(document).on('click', '#login', function(){
			  var isSubmit = true;
			  var msg = "";			  
			  if($('#account').val() == ''){
				  isSubmit = false;
				  msg = $.messager.show('请输入账号！', {placement: 'center'});
			  }else if($('#password').val() == ''){
				  isSubmit = false;
				  msg = $.messager.show('请输入密码！', {placement: 'center'});
			  }else if($('#validate').val() == ''){
				  isSubmit = false;
				  msg = $.messager.show('请输入验证码！', {placement: 'center'});
			  }
			  if(isSubmit){
			  		
			  	  if($('#autologin').is(':checked')){
			  	  	$('[name="autologin"]').val(2);
			  	  }else{
			  	  	$('[name="autologin"]').val(1);
			  	  }
				  window.Util.ajax.post("ajax_login",$('#loginForm').serialize(),function(ret){
					  if (ret.result) {
						  if("" != _ref){
							  location.href = _ref;
						  }else{
							  location.href = 'home';
						  }
					  }else{
						  $("#verifyimage").attr("src","verifyimage?"+new Date());
						  msg = $.messager.show(ret.msg, {placement: 'center'});
					  }
				  });
			  }
		  });
		  
		  $(document).keypress(function(e) {  
		       if(e.which == 13) {
		    	   $("#login").trigger("click");
			   }  
		  }); 
	  }
  };
})(window.views = window.views || {});

//自动加载
$(function(){
  window.views.login.autoload(true);
});